home *** CD-ROM | disk | FTP | other *** search
/ Ultra Pack / UltraComputing Partner Applications.iso / SunLabs / tclTK / src / tcl7.4 / tests / error.test < prev    next >
Encoding:
Text File  |  1994-12-18  |  4.6 KB  |  172 lines

  1. # Commands covered:  error, catch
  2. #
  3. # This file contains a collection of tests for one or more of the Tcl
  4. # built-in commands.  Sourcing this file into Tcl runs the tests and
  5. # generates output for errors.  No output means no errors were found.
  6. #
  7. # Copyright (c) 1991-1993 The Regents of the University of California.
  8. # Copyright (c) 1994 Sun Microsystems, Inc.
  9. #
  10. # See the file "license.terms" for information on usage and redistribution
  11. # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  12. #
  13. # @(#) error.test 1.13 94/12/17 16:19:51
  14.  
  15. if {[string compare test [info procs test]] == 1} then {source defs}
  16.  
  17. proc foo {} {
  18.     global errorInfo
  19.     set a [catch {format [error glorp2]} b]
  20.     error {Human-generated}
  21. }
  22.  
  23. proc foo2 {} {
  24.     global errorInfo
  25.     set a [catch {format [error glorp2]} b]
  26.     error {Human-generated} $errorInfo
  27. }
  28.  
  29. # Catch errors occurring in commands and errors from "error" command
  30.  
  31. test error-1.1 {simple errors from commands} {
  32.     catch {format [string compare]} b
  33. } 1
  34.  
  35. test error-1.2 {simple errors from commands} {
  36.     catch {format [string compare]} b
  37.     set b
  38. } {wrong # args: should be "string compare string1 string2"}
  39.  
  40. test error-1.3 {simple errors from commands} {
  41.     catch {format [string compare]} b
  42.     set errorInfo
  43. } {wrong # args: should be "string compare string1 string2"
  44.     while executing
  45. "string compare"
  46.     invoked from within
  47. "format [string compare]..."}
  48.  
  49. test error-1.4 {simple errors from commands} {
  50.     catch {error glorp} b
  51. } 1
  52.  
  53. test error-1.5 {simple errors from commands} {
  54.     catch {error glorp} b
  55.     set b
  56. } glorp
  57.  
  58. test error-1.6 {simple errors from commands} {
  59.     catch {catch a b c} b
  60. } 1
  61.  
  62. test error-1.7 {simple errors from commands} {
  63.     catch {catch a b c} b
  64.     set b
  65. } {wrong # args: should be "catch command ?varName?"}
  66.  
  67. test error-2.1 {simple errors from commands} {
  68.     catch catch
  69. } 1
  70.  
  71. # Check errors nested in procedures.  Also check the optional argument
  72. # to "error" to generate a new error trace.
  73.  
  74. test error-2.1 {errors in nested procedures} {
  75.     catch foo b
  76. } 1
  77.  
  78. test error-2.2 {errors in nested procedures} {
  79.     catch foo b
  80.     set b
  81. } {Human-generated}
  82.  
  83. test error-2.3 {errors in nested procedures} {
  84.     catch foo b
  85.     set errorInfo
  86. } {Human-generated
  87.     while executing
  88. "error {Human-generated}"
  89.     (procedure "foo" line 4)
  90.     invoked from within
  91. "foo"}
  92.  
  93. test error-2.4 {errors in nested procedures} {
  94.     catch foo2 b
  95. } 1
  96.  
  97. test error-2.5 {errors in nested procedures} {
  98.     catch foo2 b
  99.     set b
  100. } {Human-generated}
  101.  
  102. test error-2.6 {errors in nested procedures} {
  103.     catch foo2 b
  104.     set errorInfo
  105. } {glorp2
  106.     while executing
  107. "error glorp2"
  108.     invoked from within
  109. "format [error glorp2]..."
  110.     (procedure "foo2" line 1)
  111.     invoked from within
  112. "foo2"}
  113.  
  114. # Error conditions related to "catch".
  115.  
  116. test error-3.1 {errors in catch command} {
  117.     list [catch {catch} msg] $msg
  118. } {1 {wrong # args: should be "catch command ?varName?"}}
  119. test error-3.2 {errors in catch command} {
  120.     list [catch {catch a b c} msg] $msg
  121. } {1 {wrong # args: should be "catch command ?varName?"}}
  122. test error-3.3 {errors in catch command} {
  123.     catch {unset a}
  124.     set a(0) 22
  125.     list [catch {catch {format 44} a} msg] $msg
  126. } {1 {couldn't save command result in variable}}
  127. catch {unset a}
  128.  
  129. # More tests related to errorInfo and errorCode
  130.  
  131. test error-4.1 {errorInfo and errorCode variables} {
  132.     list [catch {error msg1 msg2 msg3} msg] $msg $errorInfo $errorCode
  133. } {1 msg1 msg2 msg3}
  134. test error-4.2 {errorInfo and errorCode variables} {
  135.     list [catch {error msg1 {} msg3} msg] $msg $errorInfo $errorCode
  136. } {1 msg1 {msg1
  137.     while executing
  138. "error msg1 {} msg3"} msg3}
  139. test error-4.3 {errorInfo and errorCode variables} {
  140.     list [catch {error msg1 {}} msg] $msg $errorInfo $errorCode
  141. } {1 msg1 {msg1
  142.     while executing
  143. "error msg1 {}"} NONE}
  144. test error-4.4 {errorInfo and errorCode variables} {
  145.     set errorCode bogus
  146.     list [catch {error msg1} msg] $msg $errorInfo $errorCode
  147. } {1 msg1 {msg1
  148.     while executing
  149. "error msg1"} NONE}
  150. test error-4.5 {errorInfo and errorCode variables} {
  151.     set errorCode bogus
  152.     list [catch {error msg1 msg2 {}} msg] $msg $errorInfo $errorCode
  153. } {1 msg1 msg2 {}}
  154.  
  155. # Errors in error command itself
  156.  
  157. test error-5.1 {errors in error command} {
  158.     list [catch {error} msg] $msg
  159. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  160. test error-5.2 {errors in error command} {
  161.     list [catch {error a b c d} msg] $msg
  162. } {1 {wrong # args: should be "error message ?errorInfo? ?errorCode?"}}
  163.  
  164. # Make sure that catch resets error information
  165.  
  166. test error-6.1 {catch must reset error state} {
  167.     catch {error outer [catch {error inner inner.errorInfo inner.errorCode}]}
  168.     list $errorCode $errorInfo
  169. } {NONE 1}
  170.  
  171. return ""
  172.